<script type="text/javascript">
	$(function(){
		$("#years").selectpicker({
    		title : '选择年级'
    	});
		$("#profesion").selectpicker({
    		title : '选择专业'
    	});
	});
	function yearss(value){
		$("#xnxq").find("option").remove();
		$('#xnxq').selectpicker('refresh');
		$("#kcjh").find("option").remove();
		$('#kcjh').selectpicker('refresh');
		$("#profesion").find("option").remove();
		$('#profesion').selectpicker('refresh');
		$.post('classSchedule/findSchoolYear',{year:value},function(data){
    		if (data.leangth==0) {
				bootbox.alert('此年份的学年学期为空数据！请添加学年学期后操作');
				}
    		for (var i = 0; i < data.length; i++) {  
                $('#xnxq').append("<option value=" + data[i].id + "> "+data[i].xnxq +"</option>"); 
                
            }  
    		var	xnxq='[[${model==null?'':model.ep.schoolyear.id}]]';
    		$('#xnxq').selectpicker('val', xnxq);
    		$('#xnxq').selectpicker('refresh');
    	});
		
		$.post('classSchedule/yearChanges',{year:value},function(data){
    		if (data.leangth==0) {
				bootbox.alert('此年份没有专业！请添加后操作');
				}
    		for (var i = 0; i < data.length; i++) {  
                $('#profesion').append("<option value=" + data[i].id + "> "+data[i].profesion +"</option>"); 
                
            }  
    		var xa ='[[${model==null?'':model.ep.curriculum.profession.id}]]';
    		$('#profesion').selectpicker('val', xa);
    		$('#profesion').selectpicker('refresh');
    	});
	}
	function profesions(value){
		
		$("#kcjh").find("option").remove();
		$('#kcjh').selectpicker('refresh');

		var result = $("#input_text").val();
		var profesionss="";
		var xnxqss="";
		if(result==""){
			 profesionss=$("#profesion").val();
			 xnxqss=$("#xnxq").val();
		}
		if(result!=""){
			 profesionss='[[${model==null?'':model.ep.curriculum.profession.id}]]';
			 xnxqss='[[${model==null?'':model.ep.Schoolyear.id}]]';
		}
		if(xnxqss!=""&&profesionss!=""){
			$("#kcjh").find("option").remove();
			$('#kcjh').selectpicker('refresh');
			var profesion=$("#profesion").val();
			$.post('classSchedule/kcjhandxq',{profesion:profesionss,schoolyearId:xnxqss},function(data){
				if (data.leangth==0) {
					bootbox.alert('没有课程计划！请添加后操作');
					}
	    		for (var i = 0; i < data.length; i++) {  
	                $('#kcjh').append("<option value=" + data[i].id + "> ["+data[i].teacher.name + "]&emsp;"+ data[i].kcmc +"</option>"); 
	                
	            }  
	    		var	kcjh='[[${model==null?'':model.ep.id}]]';
	    		$('#kcjh').selectpicker('val', kcjh);
	    		$('#kcjh').selectpicker('refresh');
	    	});
		}
	}
	function getkcjhandxq(value){
		$("#kcjh").find("option").remove();
		$('#kcjh').selectpicker('refresh');
		var profesion=$("#profesion").val();
		$.post('classSchedule/kcjhandxq',{profesion:profesion,schoolyearId:value},function(data){
			if (data.leangth==0) {
				bootbox.alert('没有课程计划！请添加后操作');
				}
    		for (var i = 0; i < data.length; i++) {  
                $('#kcjh').append("<option value=" + data[i].id + "> ["+data[i].teacher.name + "]&emsp;"+ data[i].kcmc +"</option>"); 
                
            }  
    		var	kcjh='[[${model==null?'':model.ep.id}]]';
    		$('#kcjh').selectpicker('val', kcjh);
    		$('#kcjh').selectpicker('refresh');
    	});
	}
</script>
<form id="formEdit" action="save" class="form-horizontal" role="form" >

    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">操作</h4>
            </div>
            <div class="modal-body">

            	<!-- 以下为要修改的的内容 -->

				<input type="hidden" name="modelid" id="input_text" data-th-value="${model==null?'':model.id}">
				
				<div class="row">
				    <div class="form-group col-sm-6">
							<label for="year" class="col-sm-5 control-label"><span
									class="text-red">*</span>年级</label>
							<div class="col-sm-7">
								<select id="years" name="year" class="form-control"
									onchange="yearss(this.value)">
									<option style="display: none"></option>
									<option data-th-each="years:${years}" data-th-text="${years}" data-th-value="${years}">1</option>
								</select>		
							</div>
					</div>
					<div class="form-group col-sm-6">
							<label for="profesion" class="col-sm-5 control-label"><span
									class="text-red">*</span>专业</label>
							<div class="col-sm-7">
								<select id="profesion" name="profesion" onchange="profesions(this.value)" class="form-control">
								<option style="display: none"></option>
								</select>
							</div>
					</div>
			
				</div>
				
				<div class="row">
				    <div class="form-group col-sm-6">
						<label for="xnxq" class="col-sm-5 control-label"><span
								class="text-red">*</span>学年学期</label>
						<div class="col-sm-7">
							<select id="xnxq" name="xnxqid" onchange="getkcjhandxq(this.value)" class="form-control">
							<option style="display: none"></option>
							</select>
						</div>
					</div>
					
					<div class="form-group col-sm-6">
						<label for="kcjh" class="col-sm-5 control-label"><span
								class="text-red">*</span>课程计划</label>
						<div class="col-sm-7">
							<select id="kcjh" name="kcjhid" class="form-control">
							<option style="display: none"></option>
							</select>
						</div>
					</div>
				</div>
		        
		        <div class="row">
					<div class="form-group col-sm-6">
						<label for="classroom" class="col-sm-5 control-label"><span
								class="text-red">*</span>上课教室</label>
						<div class="col-sm-7">
							<select id="classroom" name="classroomid" class="form-control">
							<option style="display: none"></option>
							</select>
						</div>
					</div>
					<div class="form-group col-sm-6">
						<label for="skxq" class="col-sm-5 control-label"><span
								class="text-red">*</span>上课星期</label>
						<div class="col-sm-7">
						       <select id="skxq" name="skxq" class="form-control"
									onchange="selectSkxq(this.value)">
									<option style="display: none"></option>
									<option data-th-each="jcb:${xq}"
										data-th-text="${jcb}">1</option>
								</select>						
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="form-group col-sm-6">
						<label for="skjc" class="col-sm-5 control-label"><span
								class="text-red">*</span>上课节次</label>
						<div class="col-sm-7">
							<select id="skjc" name="skjc" class="form-control">
							<option style="display: none"></option>
							</select>
						</div>
					</div>
				</div>
				
				
					

                <!-- 以上为要修改的内容 -->

            </div>
            <div class="modal-footer">
				<button type="button" onclick="findEp()" class="btn btn-info"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>查看未能自动安排课表的课程</button>
                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">

 	var options= {
			message: '验证不通过',
			feedbackIcons: {
                 valid: 'glyphicon glyphicon-ok',
                 invalid: 'glyphicon glyphicon-remove',
                 validating: 'glyphicon glyphicon-refresh'
             },
             fields: { 

             }
         };
        $('#formEdit').bootstrapValidator(options).on('success.form.bv', function(e) {
        	e.preventDefault();							   	//很重要没有它则会提交默认表单，不会做下面的ajax表单提交
            var fd = new FormData($("#formEdit")[0]); 
            $.ajax({  
              url: "classSchedule/save",  
              type: "POST",  
              data: fd,  
              processData: false,  // 不处理数据  
              contentType: false,   // 不设置内容类型
              success:function(result){
            	  if(result.success){
	            	  $('#myModal').modal("hide");
            	  }else{
            		  bootbox.alert(result.msg);
            	  }
              },
              error:function(result){
            	  alert(result);
              }
            });  
    	});
   
        $("#classroom").selectpicker({
    		title : '选择教室'
    	});
    	$("#skjc").selectpicker({
    		title : '选择节次'
    	});
    	
    	$("#xnxq").selectpicker({
    		title : '选择学年学期'
    	});
    	$("#skxq").selectpicker({
    		title : '选择上课星期'
    	});
    	$("#kcjh").selectpicker({
    		title : '选择课程计划'
    	});
    	
        $(function(){
        	$.post('classSchedule/classroom',function(data){
        		if (data.length==0) {
					bootbox.alert('没有教室！请添加后操作');
					}
        		for (var i = 0; i < data.length; i++) {  
                    $('#classroom').append("<option value=" + data[i].id + "> "+data[i].serialNumber +"</option>"); 
                    
                }
        		var js='[[${model==null?'':model.classroom.id}]]';
        		 $('#classroom').selectpicker('val', js);
        		
        		$('#classroom').selectpicker('refresh');
        	});
        	
        });     
      
       
        function selectSkxq(skxq,skjcval) {
    		$.post('classSchedule/getSkjc', {
    			skxq : skxq
    		}, function(result) {
    				$('#skjc').html(
    						'<option style="display: none"></option>');
    				 for (var i = 0; i < result.length; i++) {
    					$('#skjc').append(
    							"<option value='"+result[i].id+"'>" + result[i].jcsj
    									+ "</option>");
    				}
    				var skjc='[[${model==null?'':model.jcb.id}]]';
    				 $('#skjc').selectpicker('val',skjc);
    				$('#skjc').selectpicker('refresh');
    				
    		})

    	}
        
        var	skxq='[[${model==null?'':model.jcb.xq}]]';
		$('#skxq').selectpicker('val', skxq);
		selectSkxq(skxq);
		
		/* function getkcjhandxq(schoolyearid){
			$.post('classSchedule/getkcjh', {
				schoolyearid : schoolyearid
    		}, function(result) {
    				$('#kcjh').html(
    						'<option style="display: none"></option>');
    				 for (var i = 0; i < result.length; i++) {
    					$('#kcjh').append(
    							"<option value='"+result[i].id+"'>" + result[i].jcsj
    									+ "</option>");
    				}
    				var kcjh='[[${model==null?'':model.ep.id}]]';
    				 $('#kcjh').selectpicker('val',kcjh);
    				$('#kcjh').selectpicker('refresh');
    				
    		})
		} */
		
		/* 在进行修改时  使数据初始化 */
		$(function(){
			var result = $("#input_text").val();
			if(result!=""){
				var years ='[[${model==null?'':model.ep.curriculum.profession.year}]]';
				$('#years').selectpicker('val',years);
				$('#years').selectpicker('refresh');
				
				yearss(years);
				var value ='[[${model==null?'':model.ep.curriculum.profession.id}]]';
				profesions(value);
			}
			
		});
		function findEp(){
			window.open("agcs/manage");
		}
</script>